<template>
  <div>
      <div style="margin: 20px 40px;color: #ff5722;font-size: 17px; font-weight: bold;">
          <div>提示：1.最大预选人数为教学班最多允许选课的人数。</div>
          <div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.您选课后的选课状态为预选。</div>
      </div>
    <div class="assessment-container">
      <div class="table-container">
        <el-table
          :data="tableData"
          border
          class="table-data"
          row-class-name="row-class"
          cell-class-name="cell-class"
          header-row-class-name="header-row-class"
          header-cell-class-name="header-cell-class"
          style="height: 580px; overflow-y: auto"
          @selection-change="handleSelectionChange"
        >
          <el-table-column prop="teachingClass" label="课程编号" align="center">
            <template slot-scope="scoped">{{scoped.row['teachingClass'].classNo}}</template>
          </el-table-column>
          <el-table-column prop="teachingClass" label="课程名称" align="center">
            <template slot-scope="scoped">{{scoped.row['teachingClass'].className}}</template>
          </el-table-column>
          <el-table-column prop="ClassHours" label="学时" align="center">
             <template slot-scope="scoped">{{scoped.row['course'].totalHours}}</template>
          </el-table-column>
          <el-table-column prop="credit" label="学分" align="center">
            <template slot-scope="scoped">{{scoped.row['course'].credit}}</template>
          </el-table-column>
          <el-table-column prop="teachingClass" label="教学班名称" align="center">
            <template slot-scope="scoped">{{scoped.row['course'].teachingClassName}}</template>
          </el-table-column>
          <el-table-column prop="ClassTime" label="上课时间/主讲教员/上课地点" align="center" width="400">
            <template slot-scope="scoped">
              <span v-for="item in scoped.row['coursesList']">
                {{item.week}}{{item.courses}} / {{item.teacher}} / {{item.place}} ,
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="teachingClass"
            label="最大预选人数"
            width="130"
            align="center"
          >
          <template slot-scope="scoped">{{scoped.row['teachingClass'].maxNum}}</template>
          </el-table-column>
          <el-table-column
            prop="selectedNumber"
            label="已选人数"
            width="130"
            align="center"
          >
          <template slot-scope="scoped">{{scoped.row['teachingClass'].reserveNum}}</template>
          </el-table-column>
          <el-table-column label="选课" width="100" align="center" type="selection">
          </el-table-column>
          <!-- <el-table-column
            prop="checked"
            label="选课"
            width="130"
            align="center"
          >
          <template slot-scope="scope">
              <el-checkbox v-model="scope.row['checked']"></el-checkbox>
          </template>
          </el-table-column> -->
        </el-table>
      </div>
    </div>
    <div class="wrapper-container" style="width: calc(100% - 20px)">
      <div class="bottom-block" style="display: block">
      <div class="text">
        当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条
      </div>
      </div>
    <div class="pagination-block">
      <el-pagination
        prev-text="上一页"
        next-text="下一页"
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
      >
      </el-pagination>
    </div>
    </div>
    <div class="btn-caozuo">
      <el-button type="warning" @click="submitSelectClass" size="mini">确定</el-button>
    </div>
  </div>
</template>

<script>
import {wsxk_wsxkJxbList, wsxk_submit} from "@/api/trainingManagement/place.js";
export default {
  data() {
    return {
      total: 0, //总条数
      pageSize: 50, //条数
      startPage: 0, //开始条数
      endPage: 0, //结束条数
      currentPage: 1, //当前页数

      batchId: "",
      selectPlanList: [], //选中课程
      tableData: [],
    };
  },
  created() {},
  mounted() {
    this.batchId = this.$route.query.batchId;
    this.queryList();
  },
  methods: {
    // 表格数据选中
    handleSelectionChange(val) {
      this.selectPlanList = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.queryList();
    },
    async queryList() {
      const res = await wsxk_wsxkJxbList(this.batchId);
      if (res.data.code == 200) {
        this.tableData = res.data.data.records;
        this.total = res.data.data.total;
        var length = this.tableData.length;
        this.calculatePage(
          this.pageSize,
          res.data.data.current, length);
      }
    },
    // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage)  + parseInt(length) - 1;
      }
    },
    // 课程提交
    async submitSelectClass() {
      var list = [];
      if (this.selectPlanList.length > 0) {
        this.selectPlanList.forEach(item => {
          list.push(item.course.id);
        })
        var data = {
            "batchId":this.batchId,
            "list":list
        }
        const res = await wsxk_submit(data);
        if (res.data.code == 200) {
          this.$message.success("选课成功!");
          this.$router.push("/student/course/courseSelection");
        }
      } else {
        this.$message.warning("请至少选中一门课程!");
        return;
      }
    },
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
@import "../../../../styles/text.less";
/deep/ .szjky .el-dialog__body {
  height: 432px;
}
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.message-container {
  > div {
    display: inline-block;
    &:nth-child(1) {
      padding-left: 111px;
      font-size: 20px;
      color: rgba(0, 76, 167, 1);
      font-weight: bold;
      vertical-align: top;
    }
    &:nth-child(2) {
    }
  }
}
</style>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  // display: flex;
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.btn-caozuo {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  margin: 0 auto;
  padding-top: 50px;
}

.assessment-container {
  width: calc(100% - 20px);
  .table-container {
     width: 100%;
  }
}
</style>
